import { NgModule, ModuleWithProviders, APP_INITIALIZER } from '@angular/core';
import { loadIcon } from '../icon/api';
import { MessageModule } from '../message/api';
import { NotificationModule } from '../notification/api';
import { MessageboxModule } from '../messagebox/api';
import { polyfill } from './polyfills';
import { OverlayContainerModule } from './overlayContainer/overlayContainer.module';

export function appInit(): () => void {
  polyfill();
  loadIcon();
  return (): void => {};
}

@NgModule({
  imports: [MessageModule, NotificationModule, MessageboxModule, OverlayContainerModule],
})
export class CoreModule {
  static forRoot(): ModuleWithProviders<CoreModule> {
    return {
      ngModule: CoreModule,
      providers: [
        {
          provide: APP_INITIALIZER,
          useFactory: appInit,
          multi: true,
        },
      ],
    };
  }
}
